<template>
	<view class="hotel-book mainbgc">
		<!-- tab栏： -->
		<view class="topTab tabBg">
			<u-tabs :list="tabList" @click="changetab" lineColor="#00D4E2"
				itemStyle="height:88rpx; padding: 0rpx 32rpx 0rpx 32rpx;" lineWidth="30"></u-tabs>
		</view>
		<!-- 详情区域： -->
		<view class="">
			<view class="flexcenter1" v-if="!list.data.length">
				<view class="placeholderimg" style="margin-top: 300rpx;">
					<image src="../../static/images/bg-icons/placeholderimg.png" mode=""></image>
				</view>
				<view class="zanwushuju">暂无数据~</view>
			</view>
			<view class="book-list">
				<view class="book-item ffffff mainpadding border-r2" v-for="item in list.data" :key="item.id"
					style="clear: both;" @click="toOrderDetails(item.id)">
					<view class="line-one flexleft2">
						<text class="number">订单号：{{item.order_no}}</text>
						<text class="dStatus" style="color: #666;" v-show="item.checkinfo=='-1'">已取消</text>
						<text class="dStatus" v-show="item.checkinfo==1">待支付</text>
						<!-- <text class="dStatus" v-show="item.checkinfo==1">待支付（{{item.itemend}}）</text> -->
						<text class="dStatus color2" v-show="item.checkinfo==2">待入住</text>
						<text class="dStatus color2" v-show="item.checkinfo==3">已入住</text>
						<text class="dStatus color2" v-show="item.checkinfo==4">待评价</text>
						<text class="dStatus color2" v-show="item.checkinfo==5">已完成</text>
						<text class="dStatus color2" style="color: #ff0000;" v-show="item.checkinfo==6">已退款</text>
						<text class="dStatus color2" style="color: #ff6b00;" v-show="item.checkinfo==7">审核中</text>
					</view>
					<view class="line-two" v-for="ite in item.goods" :key="ite.id">
						<view class="pic">
							<image :src="item.shop.logo_text" mode=""></image>
						</view>
						<view class="details">
							<view class="title yhxiankuan">{{ite.shop_name}}</view>
							<view class="toLive">
								<text class="before-time">{{ite.start_date_text}}</text>
								<text class="after-time">后入住</text>
							</view>
							<view class="columnLine">|</view>
							<view class="toGo">
								<text class="before-time">{{ite.end_date_text}}</text>
								<text class="after-time">前住离</text>
							</view>
							<view class="money margin-top">
								总价：<text class="color1">￥{{ite.total_price}}</text>
							</view>
						</view>
					</view>
					<view class="btn-box flexleft margin-top">
						<view class="quxiao" v-show="item.checkinfo==1||item.checkinfo==2"
							@click.stop="cancelorder(item.id)">取消</view>
						<view class="zhifu" v-show="item.checkinfo==1" @click.stop="atoncepay(item)">立即支付</view>
						<view class="shanchu" v-show="item.checkinfo==5 || item.checkinfo=='-1'" @click.stop="delorder(item.id)">删除订单</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				tabList: [{
						name: '全部'
					},
					{
						name: '待付款'
					},
					{
						name: '待入住'
					},
					{
						name: '已入住'
					},
					{
						name: '已完成'
					}
				],
				currenttab: 0, //状态：0=全部，1=待付款，2=待入驻，3=已入住，4=已完成
				page: 1,
				limit: 12,
				list: {
					data: []
				},
			}
		},
		onLoad(){
			this.init()
		},
		onShow() {
			// this.init()
		},
		methods: {
			// 删除订单
			delorder(id) {
				httpRequest.modal('', '确认删除当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/order/delOrder', 'POST', {
							id
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 取消订单
			cancelorder(id) {
				httpRequest.modal('', '确认取消当前订单吗？', true, (res) => {
					if (res) {
						httpRequest.request('api/order/cancelOrder', 'POST', {
							id
						}).then(res => {
							httpRequest.toast(res.msg)
							this.init()
						})
					}
				})
			},
			// 立即支付
			atoncepay(item){
				let data = {
					id:item.id,
					pay_price:item.pay_price,
					allscore:item.allow_score,
					type:1
				}
				uni.navigateTo({
					url:'/pages/hotel/hotelorder?msg=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('api/order/myOrder', 'GET', {
					page: page || 1,
					limit: _this.limit,
					status: this.currenttab,
				}, false, false, false).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
						_this.list.data.forEach(item => {
							this.$set(item, "itemend", "")
							item.itemend = this.djstime(item.expire_tme)
						})
						setInterval(() => {
							_this.list.data.forEach(item => {
								item.itemend = this.djstime(item.expire_tme)
							})
						}, 1000)
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			djstime(endTime) {
				let startTime = (Date.parse(new Date())) / 1000;
				var timestamp = (Date.parse(new Date())) / 1000; //计算当前时间戳 (毫秒级)
				var date1 = ""; //开始时间
				if (timestamp < startTime) {
					date1 = startTime;
				} else {
					date1 = timestamp; //开始时间
				}
				var date2 = endTime; //结束时间
				// var date3 = date2.getTime() - date1.getTime(); //时间差的毫秒数
				var date3 = (date2 - date1) * 1000; //时间差的毫秒数
				//计算出相差天数
				var days = Math.floor(date3 / (24 * 3600 * 1000));
				//计算出小时数
				var leave1 = date3 % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
				var hours = Math.floor(leave1 / (3600 * 1000));
				//计算相差分钟数
				var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
				var minutes = Math.floor(leave2 / (60 * 1000));
				//计算相差秒数
				var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
				var seconds = Math.round(leave3 / 1000);
				if (hours < 10) {
					hours = "0" + hours
				}
				if (minutes < 10) {
					minutes = "0" + minutes
				}
				if (seconds < 10) {
					seconds = "0" + seconds
				}
				return hours + ":" + minutes
			},
			changetab(item) {
				console.log('item', item);
				this.currenttab = item.index
				this.init()
			},

			toOrderDetails(id) {
				uni.navigateTo({
					url: '/pages/my/jiudianxiangqing?id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabBg {
		background-color: #fff;
		// margin-bottom: 30rpx;
	}

	.book-list {
		padding: 22rpx 17rpx;
	}

	.book-item {
		overflow: hidden;
	}

	.number {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
	}

	.line-one {
		margin-bottom: 18rpx;
	}

	.dStatus {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #FF0000;
	}

	.pic {
		width: 182rpx;
		height: 286rpx;
		margin-right: 30rpx;
		border-radius: 21rpx;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.line-two {
		display: flex;
		justify-content: space-between;
	}

	.details {
		flex: 1;
	}

	.title {
		font-size: 30rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #666666;
		margin-bottom: 30rpx;
	}

	.after-time {
		font-size: 28rpx;
		color: #999999;
		margin-left: 10rpx;
	}

	.columnLine {
		margin-left: 60rpx;
	}

	.color1 {
		color: #FF5C00;
	}

	.color2 {
		color: #00D4E2;
	}

	.btn-box {
		float: right;
		padding-bottom: 40rpx;
	}

	.quxiao {
		padding: 8rpx 50rpx;
		border: 2rpx solid #666666;
		border-radius: 30rpx;
		margin-right: 25rpx;
	}

	.zhifu {
		padding: 8rpx 30rpx;
		border-radius: 30rpx;
		margin-right: 25rpx;
		background-color: #00D2E1;
		color: #fff;
		border: 2rpx solid #00D2E1;
	}

	.shanchu {
		padding: 8rpx 30rpx;
		border: 2rpx solid #666666;
		border-radius: 30rpx;
	}

	.book-item {
		margin-bottom: 30rpx;
	}

	.book-item:last-child {
		margin-bottom: 0;
	}
</style>
